<template>
  <view class="container">
    <Table ref="table" :fetchData="fetchData">
      <template #default="{ data }">
        <uni-card
          @click="cardClick(item)"
          v-for="item in data"
          :title="item.hiddenCheckType"
          :extra="item.hiddenCheckTime"
        >
          <template #title>
            <view class="title">
              <view class="title-left">
                <h3 class="title-title" style="width: 50vw">
                  {{ item.analysisUnit }}
                </h3>
                <span class="title-times">
                  {{ `每${item.cycle + item.unit + "1"}次` }}
                </span>
              </view>
              <view class="title-right">
                <span class="title-times">
                  {{ item.whetherRelease == 0 ? "已发布" : "未发布" }}
                </span>
              </view>
            </view>
          </template>
          <view class="uni-body">
            <view>{{ item.checkUserNames }}</view>
            <text>{{ item.taskStartTime }}</text>
          </view>
        </uni-card>
      </template>
    </Table>
    <button @click="saoyisao" type="primary" class="saoyisao">扫一扫</button>
  </view>
</template>

<script setup>
import { ref, onActivated } from "vue";
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import Table from "@/components/uniList.vue";
import { useAsyncData } from "@/hooks/useAsyncData.js";
import { apis as APIS } from "@/api/yhpc/pcrw.js";
import { router } from "@/router/index.js";
import { PATH } from "../paths";

const cardClick = (item) => {
  router.toPage({
    path: PATH.PCRWLIST,
    params: {
      row: JSON.stringify(item),
    },
  });
};
const table = ref();
const { fetchData, getList, queryParams } = useAsyncData({
  table,
  APIS: {
    ...APIS,
    query: APIS.parentQuery,
  },
});
onShow(() => {
  getList(true);
});

const saoyisao = () => {
  // router.toPage({
  //   path: "/pages/yhpc/pcjh/pcrwsm",
  //   params: {
  //      id: 20,
  //   },
  // });
  // return
  // 只允许通过相机扫码
  uni.scanCode({
    success: function (res) {
      let data = null
      try {
        data = JSON.parse(res.result)
      } catch (e) {
        data = res.result;
      }
      if (data instanceof Object) {
        if (data.type == "双重预防") {
          router.toPage({
            path: "/pages/yhpc/pcjh/pcrwsm",
            params: {
              id: data.id,
            },
          });
        } else {
          uni.showToast({
            title: "未识别二维码",
          });
        }
      } else {
       router.toPage({
         path: "/pages/yhpc/pcjh/pcrwsm",
         params: {
           id: data.id,
         },
       });
      }
    },
  });
};
</script>

<style lang="scss" scoped>
.container {
  padding-bottom: 12vw;
}

.saoyisao {
  position: fixed;
  bottom: 0;
  width: 100vw;
  height: 12vw;
  left: 0;
  right: 0;
}
.title {
  display: flex;
  justify-content: space-between;
  padding-top: 20upx;
  box-sizing: border-box;
  &-left {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }
  &-times {
    background-color: rgb(22, 119, 255);
    padding: 2px;
    font-size: 12px;
    border-top-left-radius: 10px;
    border-bottom-right-radius: 10px;
    margin-left: 5px;
    color: #fff;
  }

  &-right {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }
}
</style>
